package com.zpark.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zpark.common.Response;
import com.zpark.entity.*;
import com.zpark.service.impl.CvServiceImpl;
import com.zpark.service.impl.ExperienceServiceImpl;
import com.zpark.service.impl.ProjectServiceImpl;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import javax.xml.transform.Source;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author lx
 * @since 2024-03-18
 */
@RestController
@RequestMapping("/cv")
public class CvController {
    @Resource
    private CvServiceImpl cvService;
    //查询所有
    @GetMapping ("/selectAll")
    public Response selectAll(){
     List cvList=cvService.selectAll();
     return Response.success(cvList);
    }
    //根据id查询
    @GetMapping("/selectById/{id}")
    public Response selectById(@PathVariable("id") int id){

      Cv cv=  cvService.getById(id);
      return Response.success(cv);
    }
    //模糊查询
    @GetMapping("/likeQuery/{key}")
    public Response likeQuery(@PathVariable("key") String key){
       List cvs= cvService.likeQuery(key);
        return Response.success(cvs);
    }
    /**
     *cv.html
     */
    @Resource
    private ExperienceServiceImpl experienceService;
    @Resource
    private ProjectServiceImpl projectService;
    @GetMapping("/selAll")
    public Response selAll(HttpSession session){
        Member member =(Member) session.getAttribute("MEMBER");
        Integer memberId = member.getId();
        QueryWrapper<Cv> wrapper = new QueryWrapper<>();
        wrapper.eq("member_id",memberId);
        Cv cv = cvService.getOne(wrapper);
        //工作经历
        List<Experience> experienceList = experienceService.selectByCv_id(cv.getId());
        //项目经历
//        List project = projectService.selectByCvId(cv.getId());
//        System.out.println(project);
        CvInfo cvInfo = new CvInfo();
        cvInfo.setCv(cv);
        cvInfo.setExp(experienceList);
//        cvInfo.setPro(project);
        return Response.success(cvInfo);
    }
    //修改个人信息
    @PostMapping("/updateBase")
    public Response updateBase(@RequestBody Cv cv,HttpSession session){
        //和member表关
        Member member =(Member) session.getAttribute("MEMBER");
        Integer memberId = member.getId();
        cv.setMemberId(memberId);
        boolean b = cvService.updateBase(cv);
        if(b)
            return Response.success().setMessage("更新成功");
        else
            return Response.failure().setMessage("更新失败");
    }
}
